package org.hgvc.webapp.ets.jsf.beans.admin;

import org.hgvc.webapp.ets.bo.Partner;
import org.hgvc.webapp.ets.spring.service.PartnerService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;
import org.jocsb.base.util.SpringUtils;


public class AdminPartnerApprovalBean extends AbstractBean {

	private PartnerService service;
	private Partner partner;
	public static final String AB_INVOKE_ACTION="partnerApprovalInvokeAction";
	public static final String BEAN_NAME="adminPartnerApprovalBean";
	public static final String NAV_PARTNER_APPROVAL="adminPartnerApproval";
	private String reason;
	private String code;
	private String actionNo;
	
	public Partner getPartner() {
		return partner;
	}

	public void setPartner(Partner partner) {
		this.partner = partner;
	}

	public void setService(PartnerService service) {
		this.service = service;
	}
	public String getReason() {
		return reason;
	}
	public void setReason(String reason) {
		this.reason = reason;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	/*----------------------------------------------------------------------*/
	public String partnerApprovalInvokeAction(String actionNo,String... params){
		String partnerId = params[1];
		try{
			code = null;
			reason = null;
			this.actionNo = actionNo;
			partner = service.getPartnerById(partnerId);
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return NAV_PARTNER_APPROVAL.concat("_"+getRoleName());
	}
	
	
	
	public String partnerApproveAction(){
		String outcome = AdminPortalBean.NAV_ADMIN_PORTAL.concat("_"+getRoleName());
		
		try{
			if(code==null||code.length()==0){
				throw new BaseException(SpringUtils.getMessage("error.partner.code.required", new Object[]{}));
			}
			
			service.approvePartnerRegistration(partner, getThisUser(), reason, code,actionNo);
			//return AdminPortalBean.NAV_ADMIN_PORTAL;
		}catch(BaseException be){
			outcome=null;
			be.printStackTrace();
			initErrorBean(be);
		}
		
		//return null;
		return outcome;
	}
	
	public String partnerRejectAction(){
		String outcome=AdminPortalBean.NAV_ADMIN_PORTAL.concat("_"+getRoleName());
		try{
			service.rejectPartnerRegistration(partner, getThisUser(), reason,actionNo);
			//return AdminPortalBean.NAV_ADMIN_PORTAL;
		}catch(BaseException be){
			outcome=null;
			be.printStackTrace();
			initErrorBean(be);
		}
		return outcome;
		//return null;
	}
	
	public String navPortal(){
		return AdminPortalBean.NAV_ADMIN_PORTAL.concat("_"+getRoleName());
	}
	
}
